package com.webchat.connect.messagequeue.config;

import com.webchat.common.enums.messagequeue.MessageBroadChannelEnum;
import com.webchat.connect.messagequeue.consumer.redis.ArticlePushRedisQueueListener;
import com.webchat.connect.messagequeue.consumer.redis.ChatMessageRedisQueueListener;
import com.webchat.connect.messagequeue.consumer.redis.ChatNotifyRedisQueueListener;
import com.webchat.connect.messagequeue.consumer.redis.GroupVideoCallRedisQueueListener;
import com.webchat.connect.messagequeue.consumer.redis.GroupVideoUserChangeRedisQueueListener;
import com.webchat.connect.messagequeue.consumer.redis.MessageCardPushRedisQueueListener;
import com.webchat.connect.messagequeue.consumer.redis.RedPacketNotifyRedisQueueListener;
import com.webchat.connect.messagequeue.consumer.redis.WebRtcSDPRedisQueueListener;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

@Configuration
public class RedisConfig {

    @Resource
    private ChatNotifyRedisQueueListener notifyQueueListener;
    @Resource
    private ChatMessageRedisQueueListener chatMessageRedisQueueListener;
    @Resource
    private ArticlePushRedisQueueListener articlePushRedisQueueListener;
    @Resource
    private WebRtcSDPRedisQueueListener webRtcSDPRedisQueueListener;
    @Resource
    private GroupVideoCallRedisQueueListener groupVideoCallRedisQueueListener;
    @Resource
    private GroupVideoUserChangeRedisQueueListener groupVideoUserChangeRedisQueueListener;
    @Resource
    private MessageCardPushRedisQueueListener messageCardPushRedisQueueListener;
    @Resource
    private RedPacketNotifyRedisQueueListener redPacketNotifyRedisQueueListener;

    @Bean
    public RedisMessageListenerContainer container(RedisConnectionFactory redisConnectionFactory) {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        // 设置链接工厂
        container.setConnectionFactory(redisConnectionFactory);
        // 配置消息监听器
        container.addMessageListener(notifyQueueListener, new ChannelTopic(MessageBroadChannelEnum.QUEUE_CHAT_NOTIFY.getChannel()));
        container.addMessageListener(chatMessageRedisQueueListener, new ChannelTopic(MessageBroadChannelEnum.QUEUE_CHAT_MESSAGE.getChannel()));
        container.addMessageListener(articlePushRedisQueueListener, new ChannelTopic(MessageBroadChannelEnum.QUEUE_ARTICLE_PUSH_MESSAGE.getChannel()));
        container.addMessageListener(webRtcSDPRedisQueueListener, new ChannelTopic(MessageBroadChannelEnum.QUEUE_VIDEO_SDP.getChannel()));
        container.addMessageListener(groupVideoCallRedisQueueListener, new ChannelTopic(MessageBroadChannelEnum.QUEUE_GROUP_VIDEO_CALL.getChannel()));
        container.addMessageListener(groupVideoUserChangeRedisQueueListener, new ChannelTopic(MessageBroadChannelEnum.QUEUE_GROUP_VIDEO_USER_CHANGE.getChannel()));
        container.addMessageListener(messageCardPushRedisQueueListener, new ChannelTopic(MessageBroadChannelEnum.QUEUE_MESSAGE_CARD_PUSH.getChannel()));
        container.addMessageListener(redPacketNotifyRedisQueueListener, new ChannelTopic(MessageBroadChannelEnum.QUEUE_RED_PACKET_NOTIFY.getChannel()));
        return container;
    }
}
